home *** CD-ROM | disk | FTP | other *** search
Wrap
(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=David Arenillas, Antoine Potten and J.M. Folgueira Title=Culturalia(+IMDB) Description=Movie importation script for Culturalia and IMDB Site=http://www.culturalianet.com Language=ES Version=1.5 (05 Feb 2005) Requires=3.5.0 Comments=Several updates made by: folgui (folgui@bigfoot.com), RedDwarf, Hades666, KaBeCi, PolloPolea, Moises DΘniz.||Thanks to Culturalia's webmaster for his help and for providing more direct access to his database.|| License=The source code of the script can be used in another program only if full credits to script author and a link to Ant Movie Catalog website are given in the About box or in the documentation of the program. GetInfo=1 [Options] ImportLengthIMDB=0|0|0=Imports Length from Culturalia (no info)|1=Imports Length from IMDB ImportRatingIMDB=0|0|0=Imports Rating from Culturalia (no info)|1=Imports Rating from IMDB BatchMode=0|0|0=Normal working mode, prompts user when needed|1=Does not display any window, takes the first movie found ***************************************************) program Culturalia_IMDB; uses StringUtils1; const BaseURLCulturalia = 'http://www.culturalianet.com/bus/catalogo.php'; var MovieName, strTemp, donde: string; Articles: array of string; Index: integer; function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer; var i: Integer; begin result := -1; if StartAt < 0 then StartAt := 0; for i := StartAt to List.Count-1 do if Pos(Pattern, List.GetString(i)) <> 0 then begin result := i; Break; end; end; procedure AnalyzePageIMDB(Address: string); var PageText: string; Value: string; begin PageText := GetPage(Address); if pos('<title>IMDb', PageText) = 0 then begin AnalyzeMoviePageIMDB(PageText) end else begin if Pos('<b>No Matches.</b>', PageText) > 0 then begin if GetOption('BatchMode') = 0 then ShowMessage('No se ha encontrado ninguna coincidencia'); Exit; end; if GetOption('BatchMode') > 0 Then begin Value := TextBetween(PageText, '<ol><li>', '</li><li>'); Address := TextBetween(Value, '<a href="', '">'); AnalyzePageIMDB(Address); end else begin PickTreeClear; repeat Value := TextBefore(PageText, '<ol>', '<b>'); if Value <> '' then begin HTMLRemoveTags(Value); HTMLDecode(Value); PickTreeAdd(Value, ''); end; Value := TextBetween(PageText, '<ol>', '</ol>'); PageText := RemainingText; until not AddMovieTitles(Value); Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="'); if Value <> '' then PickTreeMoreLink('http://us.imdb.com' + Value); if PickTreeExec(Address) then AnalyzePageIMDB(Address); end; end; end; procedure AnalyzeMoviePageIMDB(PageText: string); var Value: string; begin // Rating if (GetOption('ImportRatingIMDB') = 1) then begin Value := TextBetween(PageText, '/rating-stars/', '/rating-vote/'); SetField(fieldRating, TextBetween(Value, '<b>', '/')); end; // Length if (GetOption('ImportLengthIMDB') = 1) then begin Value := TextBetween(PageText, '<b class="ch">Runtime:</b>' + #13#10, ' '); if Value <> '' then begin if Pos(':', Value) > 0 then SetField(fieldLength, TextAfter(Value, ':')) else SetField(fieldLength, Value); end; end; end; function AddMovieTitles(List: string): Boolean; var Value: string; Address: string; begin Result := False; Value := TextBetween(List, '<li>', '</li>'); List := RemainingText; while Value <> '' do begin Address := TextBetween(Value, '<a href="', '">'); HTMLRemoveTags(Value); HTMLDecode(Value); PickTreeAdd(Value, Address); Result := True; Value := TextBetween(List, '<li>', '</li>'); List := RemainingText; end; end; function TransformTitle(Title: string): string; var BeginPos, EndPos: Integer; Value: string; Words: array of string; Articles: array of string; Replace,Original: string; Index, CommaCount: Integer; Begin // Original Title Result:=Title; Setarraylength(Words,11); Words[0]:=' In '; Words[1]:=' On '; Words[2]:=' Of '; Words[3]:=' As '; Words[4]:=' The '; Words[5]:=' At '; Words[6]:=' And A '; Words[7]:=' And '; Words[8]:=' An '; Words[9]:=' To '; Words[10]:=' For '; SetArrayLength(Articles,35); Articles[0]:=' The'; Articles[1]:=' a'; Articles[2]:=' An'; Articles[3]:=' Le'; Articles[4]:=' L'''; Articles[5]:=' Les'; Articles[6]:=' Der'; Articles[7]:=' Das'; Articles[8]:=' Die'; Articles[9]:=' Des'; Articles[10]:=' Dem'; Articles[11]:=' Den'; Articles[12]:=' Ein'; Articles[13]:=' Eine'; Articles[14]:=' Einen'; Articles[15]:=' Einer'; Articles[16]:=' Eines'; Articles[17]:=' Einem'; Articles[18]:=' Il'; Articles[19]:=' Lo'; Articles[20]:=' La'; Articles[21]:=' I'; Articles[22]:=' Gli'; Articles[23]:=' Le'; Articles[24]:=' Uno'; Articles[25]:=' Una'; Articles[26]:=' Un'''; Articles[27]:=' O'; Articles[28]:=' Os'; Articles[29]:=' As'; Articles[30]:=' El'; Articles[31]:=' Los'; Articles[32]:=' Las'; Articles[33]:=' Unos'; Articles[34]:=' Unas'; // Count the Comma in The Title CommaCount := 0; EndPos := 0; Value := Title; repeat BeginPos := Pos(',', Value); if BeginPos > 0 then begin Delete(Value, 1, BeginPos); CommaCount := CommaCount + 1; EndPos := EndPos + BeginPos; end; until( Pos(',',Value) = 0); // Compare the Article to a list of known ones for Index := 0 to 34 do begin if Pos(Articles[Index], Value) <> 0 then begin CommaCount := 1; BeginPos := EndPos; Break; end; end; if (BeginPos > 0) and (CommaCount = 1) then begin Value := Copy(Title, BeginPos + 1, Length(Title)); Value := Trim(Value); Result := Value + ' ' + Copy(Title, 1, BeginPos - 1); end; BeginPos := Pos(': ', Result); if BeginPos > 0 then Result := StringReplace(Result, ': ', ' - '); Result := AnsiMixedCase(Result, ' '); for Index := 0 to 10 do begin if Pos(Words[Index],Result) <> 0 then begin Original := Words[Index]; Replace := AnsiLowerCase(Original); Result := StringReplace(Result, Original, Replace); end; end; Result := StringReplace(Result, ' - the ', ' - The '); Result := Trim(Result); end; procedure AnalyzePageCulturalia(Address: string); var Page, TempTit: TStringList; LineNr: Integer; Code, Title, TitleOrig, Year: string; TitleFound: Boolean; begin Page := TStringList.Create; TempTit := TStringList.Create; Page.Text := GetPage(Address); Page.Text := StringReplace(Page.Text, '<br>', #13#10); if Pos('No se ha encontrado ning·n artφculo por tφtulo', Page.Text) = 0 then begin if GetOption('BatchMode') = 0 then begin PickTreeClear; LineNr := 1; PickTreeAdd('Resultados mßs probables de la b·squeda:', ''); while LineNr + 3 < Page.Count do begin Code := TextAfter(Page.GetString(LineNr), 'Codigo = '); Title := TextAfter(Page.GetString(LineNr+1), 'Titulo = '); TitleOrig := TextAfter(Page.GetString(LineNr+2), 'Titulo original = '); Year := TextAfter(Page.GetString(LineNr+3), 'A±o = '); PickTreeAdd(Title + ' (' + TitleOrig + '), ' + Year, BaseURLCulturalia + '?catalogo=1&codigo=' + Code); LineNr := LineNr + 5; end; Page.Free; if PickTreeExec(Address) then AnalyzeMoviePageCulturalia(Address); end else begin LineNr := 1; TitleFound := True; Code := TextAfter(Page.GetString(LineNr), 'Codigo = '); Address := (BaseURLCulturalia + '?catalogo=1&codigo=' + Code); if TitleFound then AnalyzeMoviePageCulturalia(Address); Page.Free; end; end else if (GetOption('BatchMode') = 0) then ShowMessage('No se ha encontrado ninguna coincidencia por tφtulo'); end; procedure AnalyzeMoviePageCulturalia(Address: string); var Page: TStringList; Comments: string; strTitle: string; strSinopsis: string; Line: string; LineNr: Integer; strTemp: string; begin Page := TStringList.Create; Page.Text := StringReplace(GetPage(Address), '<br><br>', #13#10); Page.Text := StringReplace(Page.Text, '<br>', #13#10); strTitle := TextAfter(Page.GetString(1), 'Titulo = '); if copy(strTitle, Length(strTitle), Length(strTitle)) = '.' then begin strTemp := Copy(strTitle, 1, Length(strTitle) -1); end else begin strTemp := strTitle; end; SetField(fieldTranslatedTitle, TransformTitle(strTemp)); strTemp := TextAfter(Page.GetString(2), 'Titulo original = '); SetField(fieldOriginalTitle, TransformTitle(strTemp)); SetField(fieldYear, TextAfter(Page.GetString(3), 'A±o = ')); SetField(fieldCategory, TextAfter(Page.GetString(4), 'Genero = ')); SetField(fieldCountry, TextAfter(Page.GetString(5), 'Nacion = ')); SetField(fieldDirector, TextAfter(Page.GetString(6), 'Director = ')); SetField(fieldActors, TextAfter(Page.GetString(7), 'Actores = ')); SetField(fieldProducer, TextAfter(Page.GetString(8), 'Productor = ')); Comments := 'Gui≤n: ' + TextAfter(Page.GetString(9), 'Guion = '); Comments := Comments + #13#10 + 'Fotografφa: ' + TextAfter(Page.GetString(10), 'Fotografia = '); Comments := Comments + #13#10 + 'M·sica: ' + TextAfter(Page.GetString(11), 'Musica = '); SetField(fieldComments, Comments); LineNr := FindLine('Sinopsis = ', Page, 0); Line := Page.GetString(LineNr); strSinopsis := TextAfter(Line, 'Sinopsis = '); LineNr := LineNr + 1; Line := Page.GetString(LineNr); while pos('URL = ', Line) = 0 do begin strSinopsis := strSinopsis + #13#10 + Line; LineNr := LineNr + 1; Line := Page.GetString(LineNr); end HTMLRemoveTags(strSinopsis); SetField(fieldDescription, StringReplace(StringReplace(strSinopsis, 'ô', '"'), 'ö', '"')); LineNr := FindLine('URL = ', Page, 0); if LineNr <> -1 then SetField(fieldURL, TextAfter(Page.GetString(LineNr), 'URL = ')); LineNr := FindLine('Imagen = ', Page, 0); if LineNr <> -1 then GetPicture(TextAfter(Page.GetString(LineNr), 'Imagen = ')); Page.Free; end; begin SetArrayLength(Articles,11); Articles[0]:='Lo '; Articles[1]:='La '; Articles[2]:='Le '; Articles[3]:='Uno '; Articles[4]:='Una '; Articles[5]:='Un '; Articles[6]:='El '; Articles[7]:='Los '; Articles[8]:='Las '; Articles[9]:='Unos '; Articles[10]:='Unas '; if CheckVersion(3,5,0) then begin MovieName := ''; MovieName := GetField(fieldTranslatedTitle); donde := '&donde=1'; if MovieName = '' then begin MovieName := GetField (fieldOriginalTitle); donde := '&donde=2'; end if MovieName = '' then begin Input('Importar de Culturalia', 'Introduzca el Titulo de la Pelicula:', MovieName); donde := '&donde=1'; end If MovieName <> '' then begin // Eliminate spanish article if exists for Index := 0 to 10 do begin if Pos(Articles[Index], MovieName) <> 0 then MovieName := copy(MovieName, length(Articles[Index]), length(MovieName)); end; // Eliminate point(s) at final of MovieName before search strTemp := MovieName; if Copy(strTemp, Length(strTemp), Length(strTemp)) = '.' then MovieName := Copy(strTemp, 1, Length(strTemp) -1); AnalyzePageCulturalia(BaseURLCulturalia + '?catalogo=1&texto=' + UrlEncode(MovieName) + donde); if (GetOption('ImportRatingIMDB')=1) or (GetOption('ImportLengthIMDB')=1) then AnalyzePageIMDB('http://imdb.com/find?more=tt;q='+UrlEncode(GetField(fieldOriginalTitle))); end; end else ShowMessage('Este script requiere una versi≤n mßs reciente de Ant Movie Catalog (al menos la versi≤n 3.5.0)'); end.